package com.briup.estore.controller;

import java.util.Arrays;
import java.util.Map;

import com.briup.estore.common.utils.PageUtils;
import com.briup.estore.common.utils.R;
import com.briup.estore.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.briup.estore.entity.CollectEntity;
import com.briup.estore.service.CollectService;

import javax.servlet.http.HttpSession;


/**
 * @author adam
 * @email xueyz@briup.com
 * @date 2023-03-30 14:35:49
 */
@Controller
@Slf4j
public class CollectController {
    @Autowired
    private CollectService collectService;


    /**
     * 信息
     */
    @GetMapping("/findCollect")
    @ResponseBody
    public boolean info(Long shopId,HttpSession session) {
        UserEntity user = (UserEntity) session.getAttribute("user");
        boolean flag = collectService.findCollectByUser(user.getId(), shopId);
        return flag;
    }

    /**
     * 保存用户的收藏信息
     */
    @ResponseBody
    @GetMapping("/{userId}/addCollect")
    public String addCollect(@PathVariable Long userId, CollectEntity collect) {
        collect.setUserId(userId);
        collectService.save(collect);
        return "";
    }



    /**
     * 删除
     */
    @GetMapping("/delCollect")
    public R delete( Long collectId) {
        collectService.removeById(collectId);
        return R.ok();
    }

}
